package com.lxg.controller.historyController;

import com.lxg.pojo.History;
import com.lxg.service.historyService.HistoryShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
public class HistoryController {
    @Autowired
    HistoryShowService historyShowService;

    /**
     * 查询全部借阅的历史记录
     * @return
     */
    @RequestMapping("/getAllHistory")
    public String getAllHistory(HttpSession session){
        ArrayList<History> allHistory = historyShowService.getAllHistory();
        session.setAttribute("allHistory",allHistory);
        return "/index";
    }


    /**
     * 查询全部未还借阅记录
     * @return
     */
    @RequestMapping("/getAllBorrowing")
    public String  getAllBorrowing(HttpSession session){
        ArrayList<History> allBorrowing = historyShowService.getAllBorrowing();
        session.setAttribute("allBorrowing",allBorrowing);
        return "/index";
    }


    /**
     * 查询全部已还借阅记录
     * @return
     */
    @RequestMapping("/getAllReturned")
    public String getAllReturned(HttpSession session){
        ArrayList<History> allReturned = historyShowService.getAllReturned();
        session.setAttribute("allReturned",allReturned);
        return "/index";
    }


    /**
     * 根据uid查询该用于所有借阅记录
     * @param uid
     * @return
     */
    @RequestMapping("/getAllHistoryByUid")
    public String getAllHistoryByUid(Integer uid,HttpSession session){
        ArrayList<History> allHistoryByUid = historyShowService.getAllHistoryByUid(uid);
        session.setAttribute("allHistoryByUid",allHistoryByUid);
        return "/index";
    }


    /**
     * 根据uid查询全部未还借阅记录
     * @return
     */
    @RequestMapping("/getAllBorrowingByUid")
    public String getAllBorrowingByUid(Integer uid,HttpSession session){
        ArrayList<History> allBorrowingByUid =
                historyShowService.getAllBorrowingByUid(uid);
        session.setAttribute("allBorrowingByUid",allBorrowingByUid);
        return "/index";
    }


    /**
     * 根据uid查询全部已还借阅记录
     * @return
     */
    @RequestMapping("/getAllReturnedByUid")
    public String getAllReturnedByUid(Integer uid,HttpSession session){
        ArrayList<History> allReturnedByUid =
                historyShowService.getAllReturnedByUid(uid);
        session.setAttribute("allReturnedByUid",allReturnedByUid);
        return "/index";
    }


    /**
     * 根据hid查询历史记录
     * @return
     */
    @RequestMapping("/getHistoryByHid")
    public String  getHistoryByHid(Integer hid,HttpSession session){
        History historyByHid = historyShowService.getHistoryByHid(hid);
        session.setAttribute("historyByHid",historyByHid);
        return "/index";
    }
}
